<?php

namespace app\admin\controller;

use app\admin\model\Pay as PayModel;
use app\admin\validate\Pay as PayValidate;

/**
 * 支付设置.
 */
class Pay extends Controller
{
    protected function initialize()
    {
        parent::initialize();
    }

    /**
     * 获取支付配置.
     */
    public function get()
    {
        $model = new PayModel();
        $type = input('type');
        if (empty($type)) {
            return fail('类型有误');
        }

        return $model->get($type);
    }

    /**
     * 编辑支付配置.
     */
    public function set()
    {
        $data = input('post.');
        $validate = new PayValidate();
        $type = input('type');
        if (empty($type)) {
            return fail('类型有误');
        }
        if (!$validate->scene($type)->check($data)) {
            return fail($validate->getError());
        }

        $model = new PayModel();

        return $model->set($data);
    }

    /**
     * 上传支付证书.
     */
    public function uploadCert()
    {
        $model = new PayModel();

        return $model->uploadCert();
    }
}
